/**
 * 
 */
package com.alstudio.module.xmpp.protocol.xmpp.util.xmlcreator.iq.usersaction;

import com.alstudio.module.xmpp.protocol.xmpp.packact.ALXmppDomainConfig;
import com.alstudio.module.xmpp.protocol.xmpp.packact.IQNameSpace;
import com.alstudio.module.xmpp.protocol.xmpp.util.xmlcreator.AlXmlTag;
import com.alstudio.module.xmpp.protocol.xmpp.util.xmlcreator.iq.BaseIQTemplate;

/**
 * @author alonso lee
 * 
 */
public class DeletFriendAndFanIQCreator extends BaseIQTemplate {

	private final String jid;
	private final int type;
	private final int DELETE_MY_FRIEND = 0;
	private final int DELETE_FANS = 1;

	/**
	 * 
	 */
	public DeletFriendAndFanIQCreator(String jid, int type, String domain) {
		// TODO Auto-generated constructor stub
		this.jid = jid;
		this.domain = domain;
		this.type = type;
		this.to = "favorites.";
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.alstudio.module.xmpp.protocol.xmpp.util.xmlcreator.iq.BaseIQTemplate
	 * #getIQXml()
	 */
	@Override
	public String getIQXml() {
		// TODO Auto-generated method stub
		String ns = IQNameSpace.NS_DELETE_FAVORITE;
		AlXmlTag tag = null;
		switch (type) {
		case DELETE_MY_FRIEND:
			tag = new AlXmlTag("jid");
			tag.setText(jid);
			tagList.add(tag);
			break;
		case DELETE_FANS:
			ns = IQNameSpace.NS_DELETE_FANS;
			tag = new AlXmlTag("item");
			tag.setText(jid);
			tag.setAtt("jid", jid);
			tagList.add(tag);
			break;
		}

		mALIQCreator.setNs(ns);

		mALIQCreator.setType(IQ_TYPE_SET);
		to = ALXmppDomainConfig.getALXmppDomainConfig().getDomainByNameSpace(ns);
		mALIQCreator.setTo(to + domain);

		mALIQCreator.setTagList(tagList);
		String xml = "";
		try {
			xml = mALIQCreator.getXml();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return xml;
	}

}
